package com.lijinjiang.annotation03;

import java.lang.reflect.Method;
import java.util.Arrays;

/**
 * @ClassName AnnotationDemo
 * @Description TODO
 * @Author Li
 * @Date 2022/9/21 11:04
 * @ModifyDate 2022/9/21 11:04
 * @Version 1.0
 */
public class AnnotationDemo {
    public static void main(String[] args) {
        // 1.获取class对象
        Class c = BookStore.class;
        // 2.判断是否有Book注解
        if (c.isAnnotationPresent(Book.class)){
            Book book = (Book) c.getDeclaredAnnotation(Book.class);
            System.out.println("========================");
            System.out.print(book.value());
            System.out.print(book.price());
            System.out.println(Arrays.toString(book.authors()));
        }
        Method[] methods = c.getDeclaredMethods();
        for (Method method : methods) {
            Book book = (Book) method.getDeclaredAnnotation(Book.class);
            System.out.println("========================");
            System.out.print(book.value());
            System.out.print(book.price());
            System.out.println(Arrays.toString(book.authors()));
        }
    }
}
